﻿using AnQinFrameWorkAPI.Entity.SystemCore.DTO.Login;
using AnQinFrameWorkAPI.Service.SystemCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.SystemCore;

/// <summary>
///     登录接口
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "SystemCore")]
public class LoginController : ControllerBase
{
    /**
     * 登录业务接口
     */
    private readonly LoginService _loginService;

    /**
     * 构造函数注入
     */
    public LoginController(LoginService loginService)
    {
        _loginService = loginService;
    }

    /// <summary>
    ///     登录
    /// </summary>
    [HttpPost]
    public async Task<IActionResult> Login([FromBody] LoginDTO loginDTO)
    {
        var response = await _loginService.UserLogin(loginDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     校验token
    /// </summary>
    [HttpGet("GetUserDetail")]
    [Authorize]
    public async Task<IActionResult> HandShake()
    {
        var response = await _loginService.GetUserDetail();
        return StatusCode(response.Status, response);
    }
}